#pragma once
#include <Windows.h>
#include <cmath>
#include <tchar.h>
#include <cstdio>

#include "hsltorgb.h"

#define background_color 0x00202020

struct star {
	int x,
		y,
		speed,
		r,
		g,
		b,
		fadelength;
};

struct sbutton {
	int x,
		y,
		sizeX,
		sizeY;
	bool bOver,
		 bDown;
};

class imGFX {
private:
	unsigned char *p_dib;
	
	bool bAttached;

	PAINTSTRUCT ps;

	// gradient stuff
	int iColorIndex;
	char* gradient;
	bool increasing;
	double phase1,
		   phase2, 
		   phase3;
	// sine stuff
	int x_offset,
		x_rate,
		y_rate,
		*sine_table;

	bool table_generated;

	// shapewindow 
	int SavedDC;
	HBITMAP bFace;
	HDC hFaceDC;

	int Wrap(int, const int, const int);

	int fadecounter;

public:
	HBITMAP hBMAP;
	HWND m_hWnd;
	HDC  m_dc;
	HDC  t_dc;
	UINT_PTR uTimer;

	int dib_width,
		dib_height,
	    dib_x_off,
		dib_y_off;

	RECT rNfo;

	int nfo_y_off;

	bool bNfo; // if nfo is showing

	bool Attach(HWND hWnd);
	void Detach();

	void ShapeWindow(int IDBBitmap);
	void LoadResBitmap(int IDBBitmap, unsigned char* lpBits);
	void DrawBitmap(unsigned char* lpBits, int x, int y, int sizex, int sizey);
	void DumpBitmap(int IDBBitmap, char* FileName);
	
	void AddPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b);	// SetPixel() for dibs
	void AddTranPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
	DWORD GetDIBPixel(int x, int y);

	void DrawRect(int x, int y, int width, int height, unsigned char r, unsigned char g, unsigned char b); // DrawRect for dibs
	void DrawDot(int x, int y);

	void DrawNfo(TCHAR* nfo);

	void DrawButton(sbutton button, TCHAR* Text, unsigned int r, unsigned int g, unsigned int b);

	bool IsOver(sbutton area, LPARAM lParam);

	void TextColor(unsigned char r, unsigned char g, unsigned char b);
	void VanillaText(int x, int y, TCHAR* Text);
	void PrintText(int x, int y, TCHAR* Text, unsigned char r, unsigned char g, unsigned char b);
	void ScrollText(int y, TCHAR* Text);
	void WaveBanner(int x, int y, TCHAR* Text);
	void GenerateTable();
	//void AddText(unsigned char* Font, TCHAR* Text, int x, int y, int fontx, int fonty);
	
	void CreateRainbows();

	void CreateGradient(unsigned char* outpalette, DWORD fromColor, DWORD toColor, int steps);

	void ShowNfo();

	bool Update();
	void Clear();
	void Primer();

	imGFX(int, int, int, int);
	imGFX();
	~imGFX();
};